package com.lims.algorithm.refers2offer.array;

import java.util.Scanner;

/**
 * <功能简述>
 * 斐波那契数列
 *
 * @author: lims
 * @create: 2019-04-19 17:50
 */
public class Fibonacci {
    //递归法
    public static int fibonacci(int n) {
        if (n <= 0) {
            return 0;
        } else if (n == 1 || n == 2) {
            return 1;
        } else {
            return fibonacci(n - 1) + fibonacci(n - 2);
        }
    }

    public static void main(String[] args) {
        System.out.println("请输入：");
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        System.out.println("第" + n + "项为：" + fibonacci(n));
    }
}
